package cn.com.haopy.yue.ai.db.service.hos.impl;

import cn.com.haopy.yue.ai.db.entity.arisk.AIRiskStandardCharges;
import cn.com.haopy.yue.ai.db.mapper.arisk.AIRiskStandardChargesMapper;
import cn.com.haopy.yue.ai.db.service.BaseServiceImpl;
import cn.com.haopy.yue.ai.db.service.hos.AIRiskStandardChargesService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Objects;

/**
 * @Description: TODO
 * @Author DuTao
 * @Date 2025/3/26 9:13
 */
@Service
public class AIRiskStandardChargesServiceImpl extends BaseServiceImpl<AIRiskStandardChargesMapper, AIRiskStandardCharges> implements AIRiskStandardChargesService {

    @Override
    public Page<AIRiskStandardCharges> querySelective(String name, Integer page, Integer size, String sort, String order) {

        QueryWrapper<AIRiskStandardCharges> queryWrapper = new QueryWrapper<>();
        if (StringUtils.hasText(name)) {
            queryWrapper.lambda().like(AIRiskStandardCharges::getName, name);
        }
        if (StringUtils.hasText(sort) && StringUtils.hasText(order)) {
            queryWrapper.orderBy(true, "asc".equals(order), sort);
        }
        return super.page(new Page<>(page, size), queryWrapper);
    }

    @Override
    public List<AIRiskStandardCharges> listAll(String keyWord, Integer limit) {
        QueryWrapper<AIRiskStandardCharges> queryWrapper = new QueryWrapper<>();
        if (StringUtils.hasText(keyWord)) {
            queryWrapper.lambda().like(AIRiskStandardCharges::getName, keyWord);
        }
        queryWrapper.lambda().orderByAsc(true, AIRiskStandardCharges::getSortIndex);
        if (Objects.nonNull(limit)) {
            queryWrapper.last(" limit " + limit);
        }
        return super.list(queryWrapper);
    }

    @Override
    public List<AIRiskStandardCharges> myCollect(Integer userId) {
        return super.baseMapper.myCollect(userId);
    }

    @Override
    public List<AIRiskStandardCharges> listCalculate() {
        QueryWrapper<AIRiskStandardCharges> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().orderByAsc(true, AIRiskStandardCharges::getSortIndex);
        queryWrapper.lambda().eq(AIRiskStandardCharges::getIsCalculate, Boolean.TRUE);
        return super.list(queryWrapper);
    }
}
